package cn.wizzer.app.web.modules.controllers.platform.user.chat.group;


import cn.wizzer.app.user.modules.models.GroupApply;
import cn.wizzer.app.user.modules.models.enums.GroupApplyEnum;
import cn.wizzer.app.user.modules.services.GroupApplyService;
import cn.wizzer.app.web.commons.utils.StringUtil;
import cn.wizzer.framework.util.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

/**
 * 群举报
 *
 * @author .
 */
@IocBean
@At("/platform/user/group/apply")
public class GroupApplyController {

    @Inject
    @Reference
    private GroupApplyService groupApplyService;

    @At("/")
    @Ok("beetl:/platform/user/chat/group/apply.html")
    @RequiresPermissions("user.group.apply.list")
    public void index() {
    }


    /**
     * 查询（分页）
     *
     * @param groupName   群名
     * @param userKeyword 用户信息
     * @param searchDate  日期
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @At
    @Ok("json:full")
    @RequiresPermissions("user.group.apply.list")
    public Object data(@Param("groupName") String groupName,
                       @Param("userKeyword") String userKeyword,
                       @Param("status") String status,
                       @Param("searchDate") String[] searchDate,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize) {
        return Result.success().addData(groupApplyService.listPage(groupName, userKeyword, status, searchDate, pageNumber, pageSize));
    }

    /**
     * 同意申请
     *
     * @param groupApply
     * @return
     */
    @At("/agree")
    @Ok("json:full")
    @RequiresPermissions("user.group.apply.edit")
    public Object agree(GroupApply groupApply) {
        groupApplyService.agree(groupApply);
        return Result.success();
    }

    /**
     * 拒绝申请
     *
     * @param groupApply
     * @return
     */
    @At("/refuse")
    @Ok("json:full")
    @RequiresPermissions("user.group.apply.edit")
    public Object refuse(GroupApply groupApply) {
        groupApplyService.refuse(groupApply, StringUtil.getPlatformUid());
        return Result.success();
    }

    /**
     * 删除申请记录
     *
     * @param id
     * @return
     */
    @At("/delete/?")
    @Ok("json:full")
    @RequiresPermissions("user.group.apply.delete")
    public Object delete(String id) {
        groupApplyService.delete(id);
        return Result.success();
    }

    /**
     * 申请记录状态枚举
     *
     * @return
     */
    @At
    @Ok("json:full")
    @RequiresPermissions("user.group.apply.list")
    public Object status() {
        return Result.success(GroupApplyEnum.toList());
    }
}
